// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    current: 'homepage',
    background: [
      'https://p1.music.126.net/OsDWtc_rYd6WoEAHJnTcOw==/109951167182464801.jpg?imageView&quality=89',
      'https://p1.music.126.net/6C04P1_29exmTwvDbW21Cw==/109951167181744198.jpg?imageView&quality=89',
      '	https://p1.music.126.net/28mU3eBqIWSlULhzrxCvUA==/109951167181646682.jpg?imageView&  quality=89'
    ],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    userInfo: {},
    value1: '',
    value2: '',
    value3: '',
    value4: '',
    current: 'homepage',
    tangList: '',
    obj: {
      // name:'',
    }
  },
  handleChange({
    detail
  }) {
    // if (detail.key=="homepage") 
    // {
    //   wx.navigateTo({
    //     url: '../first/first',
    //   })
    // }
    switch (detail.key) {
      case "mine":
        wx.navigateTo({
          url: '../my/my',
        })
      default:
        break;
    }
    this.setData({
      current: detail.key
    });
  },
  // 事件处理函数

  // confirm(){
  // 1.判断输入框数值是否为空，openid
  // 2.请求后台提供的添加，API
  // 3.跳转页面，输入框值数据不为空
  // }
  bindViewTap() {
    if (this.data.value1 != '') {
      if (this.data.value2 != '') {
        if (this.data.value3 != '') {
          if (this.data.value4 != '') {
            console.log(this.data.value1);
            console.log(this.data.value2);
            console.log(this.data.value3);
            console.log(this.data.value4);
            wx.showToast({
              title: '提交成功',
              duration: 2000
            })
            wx.navigateTo({
              url: '../logs/logs'
            })
          } else {
            wx.showToast({
              title: '请输入内容',
              icon: 'error',
              duration: 2000
            })
          }
        } else {
          wx.showToast({
            title: '请输入内容',
            icon: 'error',
            duration: 2000
          })
        }
      } else {
        wx.showToast({
          title: '请输入内容',
          icon: 'error',
          duration: 2000
        })
      }
    } else {
      wx.showToast({
        title: '请输入内容',
        icon: 'error',
        duration: 2000
      })
    }
    var obj = {};
    obj.name = this.data.value1;
    obj.name1 = this.data.value2;
    obj.text = this.data.value3;
    obj.text1 = this.data.value4;
    wx.cloud.callFunction({
      name: 'quickstartFunctions',
      config: {
        env: this.data.envId
      },
      data: {
        type: 'tangSelectRecord',
        obj: obj
      }
    }).then((resp) => {
      console.log('1122', resp);
      this.setData({
        tangList: resp.result.data
      });
      wx.hideLoading();
    }).catch((e) => {
      console.log(e);
      this.setData({
        showUploadTip: true
      });
      wx.hideLoading();
    });
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile(e) {
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})